{% extends "base/base.html" %}

{% block title %}
Registry | SwarmOps - Docker管理平台
{% endblock %}

{% block container %}

{% set tags = g.registry._list_repository_tag(imageName) %}
<div>
    <p><scan class="glyphicon glyphicon-info-sign"></scan>私有仓地址:&nbsp;<kbd>{{ g.registry.url }}</kbd></p>
    <p><scan class="glyphicon glyphicon-info-sign"></scan>私有仓版本:&nbsp;<kbd>v{{ g.registry.version }}</kbd></p>
    <p><scan class="glyphicon glyphicon-info-sign"></scan>私有仓状态:
    {% if g.registry.status %}
        <b class="text-success">OK</b>
    {% else %}
        <b class="text-danger">Fail</b>
    {% endif %}
    <p><scan class="glyphicon glyphicon-info-sign"></scan>当前标签数量:&nbsp;<span class="badge">{{ tags|length }}</scan></p>
    </p>
    <div>
        <ol class="breadcrumb">
            <li>Registry</li>
            <li class="active">ImageName</li>
            <li>ImageInfo</li>
        </ol>
    </div>
</div>
{% if g.registry.status %}
<table class="table table-bordered table-hover table-condensed table-responsive">
    <thead>
        <tr class="active">
            <th style="vertical-align: middle; text-align: center;">Tag</th>
            <th style="vertical-align: middle; text-align: center;">Id</th>
            <th style="vertical-align: middle; text-align: center;">Operations</th>
        </tr>
    </thead>
    <tbody>
    {% for tag, imageId in tags.iteritems() %}
        <tr>
            <td style='vertical-align: middle; text-align: center;'>{{ "{}/{}:{}".format(g.registry.url.split("://")[-1].strip("/"), imageName, tag) }}</td>
            <td style='vertical-align: middle; text-align: center;'>
                {% if g.registry.version ==1 %}
                <a href="{{ url_for('ui.registryImageId', imageId=imageId, imageName=imageName) }}" target="_blank">{{ imageId }}</a>
                {% else %}
                <a href="{{ url_for('ui.registryImageId', imageId=tag, imageName=imageName) }}" target="_blank">{{ imageId }}</a>
                {% endif %}
            </td>
            <td style='vertical-align: middle; text-align: center;'>
                <a href="javascript:DeleteTag('{{ tag }}')" title="确认删除标签: {{ tag }}&nbsp;?"><scan class="text-danger glyphicon glyphicon-trash"></scan></a>
            </td>

        </tr>
    {% endfor %}
    </tbody>
</table>
{% endif %}

{% endblock %}

{% block script %}
<script type="text/javascript">
// 更新导航
var NavId=null;
var As=document.getElementById('tab').getElementsByTagName('li');
NavId = As[4];
console.log(NavId)
NavId.className='active';

// 删除某镜像tag
function DeleteTag(tag) {
    $.ajax({
        url: "{{ url_for('apis.core.registry') }}?repository_name={{ imageName }}&repository_name_tag=" + tag,
        method: 'DELETE',
        datatype: 'json',
        success: function(res) {
            console.log(res);
            if (res.success==true) {
                layer.msg("{{ imageName }}:" + tag +", 标签删除成功！", {icon: 1});
                window.location.reload();
            } else {
                layer.msg("{{ imageName }}:" + tag +", 标签删除失败！", {icon: 2, time: 15*1000});
            }
        },
        error: function(error){
            console.log(error);
        }
    });
}

</script>
{% endblock %}
